package rsshunter;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
import parsers.Parser;

/**
 * Class representing RSSBase object.
 */
public class RSSBase {
    // Rss type base

    public static final byte RSS = 1;
    // Html type base
    public static final byte HTML = 2;
    private String name;
    private String created;
    private String notify;
    private byte type;
    private int frequency;
    private Parser parser;

    public RSSBase(String name) {
        super();
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

        this.name = name;
        this.created = df.format(new Date());
        this.notify = "E-mail";
        this.frequency = 60;
    }

    public RSSBase(String name, byte type, String created, String notify, int frequency) {
        this.name = name;
        this.type = type;
        this.created = created;
        this.notify = notify;
        this.frequency = frequency;
    }

    /**
     * Check base for new content.
     */
    public void check() {
        parser.checkBase(this);
    }

    public byte getType() {
        return type;
    }

    public void setType(byte type) {
        this.type = type;
    }

    public void setParser(Parser parser) {
        this.parser = parser;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getCreated() {
        return created;
    }

    public void setCreated(String created) {
        this.created = created;
    }

    public String getNotify() {
        return notify;
    }

    public void setNotify(String notify) {
        this.notify = notify;
    }

    public int getFrequency() {
        return frequency;
    }

    public void setFrequency(int frequency) {
        this.frequency = frequency;
    }

    @Override
    public boolean equals(Object o) {
        if (o instanceof RSSBase) {
            RSSBase other = (RSSBase) o;
            if (name.equals(other.getName())) {
                return true;
            }
        }
        return false;
    }

    @Override
    public int hashCode() {
        int hash = 5;
        hash = 13 * hash + (this.name != null ? this.name.hashCode() : 0);
        return hash;
    }
}
